import { combineReducers, createStore, applyMiddleware, compose } from "redux";
import CreateSagaMiddleware, { END } from "redux-saga";
import { routerReducer, routerMiddleware } from "react-router-redux";
import createHistory from "history/createBrowserHistory";
// import { createLogger } from "redux-logger";
//import DevTools from '../pages/DevTools/DevTools'
import reducers from "../reducers";

export default function configureStore(initialState) {
  const sagaMiddleware = CreateSagaMiddleware();
  const history = createHistory();
  const routeMiddleware = routerMiddleware(history);
  // const loggerMiddleware = createLogger(); // 日志打印

  const store = createStore(
    combineReducers({
      ...reducers,
      router: routerReducer
    }),
    initialState,
    (window && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
      ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
      : compose)(applyMiddleware(routeMiddleware, sagaMiddleware))
  );
  store.runSaga = sagaMiddleware.run;
  store.close = () => store.dispatch(END);
  store.history = history;
  return { store };
}
